package net.zjitc.service.impl;

import net.zjitc.mapper.AdminMapper;
import net.zjitc.pojo.Admin;
import net.zjitc.service.AdminService;
import net.zjitc.utils.MD5WithSaltUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    /**
     * 验证用户是否登录成功
     * @param username
     * @param password
     * @return
     */
    @Override
    public Admin findByUsername(String username, String password) {
        Admin admin =  adminMapper.findByUsername(username);
        if (admin!=null){
            //密码加密
            String pass = MD5WithSaltUtil.hashPasswordWithSalt(password, admin.getSalt());
            if (pass.equals(admin.getPassword())){
                return admin;
            }
        }

        return null;
    }
}
